home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
vbdatabs
/
pscript.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-03-14
|
29KB
|
915 lines
// ------------------------------- //
// -------- Start of File -------- //
// ------------------------------- //
// ----------------------------------------------------------- //
// C++ Source Code File Name: pscript.cpp
// Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
// Produced By: Doug Gaer
// File Creation Date: 12/17/1997
// Date Last Modified: 03/15/1999
// Copyright (c) 1997 Douglas M. Gaer
// ----------------------------------------------------------- //
// ------------- Program Description aond Details ------------- //
// ----------------------------------------------------------- //
/*
The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
All those who put this code or its derivatives in a commercial
product MUST mention this copyright in their documentation for
users of the products in which this code or its derivative
classes are used. Otherwise, you have the freedom to redistribute
verbatim copies of this source code, adapt it to your specific
needs, or improve the code and release your improvements to the
public provided that the modified files carry prominent notices
stating that you changed the files and the date of any change.
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
CORRECTION.
The PostScriptDrv class is used to create postscript documents.
This version prints postscript documents to a file.
*/
// ----------------------------------------------------------- //
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <math.h> // For ceil() function
#include "pscript.h"
// PostScript fonts
const char *PostScriptFonts[NumberOfFonts] = {
// Courier fonts
"Courier", // COURIER
"Courier-Bold", // COURIER_BOLD
"Courier-Oblique", // COURIER_OBLIQUE
"Courier-BoldOblique", // COURIER_BOLD_OBLIQUE
// Times-Roman fonts
"Times-Roman", // TIMES
"Times-Bold", // TIMES_BOLD
"Times-Italic", // TIMES_ITALIC
"Times-BoldItalic", // TIMES_BOLD_ITALIC
// Helvetica fonts
"Helvetica", // HELV
"Helvetica-Bold", // HELV_BOLD
"Helvetica-Oblique", // HELV_OBLIUQE
"Helvetica-BoldOblique", // HELV_BOLD_OBLIQUE
// Symbol font
"Symbol" // SYMBOL
};
// PostScript command strings defined in the postscript prologue
const char *BACKSPACE = "B";
const char *ENDPAGE = "EP";
const char *LINETO = "L";
const char *MOVETO = "M";
const char *NEWPATH = "NP";
const char *SHOW = "S";
const char *STARTPAGE = "SP";
const char *STROKE = "ST";
const char *TAB = "T";
void GetSystemTime(char *s, int full_month_name)
// Stand alone function use to create a custom time string for
// PostScript headers.
{
time_t STime;
struct tm *TimeBuffer;
char month[25]; char day[25]; char year[25];
char hour[25]; char minutes[25]; char seconds[25];
time(&STime);
TimeBuffer = localtime(&STime);
if(full_month_name)
strftime(month, 25, "%B", TimeBuffer);
else
strftime(month, 25, "%b", TimeBuffer);
strftime(day, 25, "%d", TimeBuffer);
strftime(year, 25, "%Y", TimeBuffer);
strftime(hour, 25, "%H", TimeBuffer);
strftime(minutes, 25, "%M", TimeBuffer);
strftime(seconds, 25, "%S", TimeBuffer);
// Weekday Name Month Day, Year HH:MM:SS
sprintf(s, "%s %s, %s %s:%s:%s", month, day, year, hour, minutes, seconds);
}
PostScriptDrv::PostScriptDrv()
{
ncopies = 1; // Print at least one copy of this document
landscape = 0; // Use portrait mode by default
use_header = 0; // Do not use headers and trailers by default
use_lr_margin = 0; // Do not use left and right margins by default
use_tb_margin = 0; // Do not use top and bottom margins by default
document_name = 0; // Name of this document
date_string = 0; // Time and date this document was printed
draw_header_line = 0; // Do not draw line between header and document
tabstop = DEFAULT_TAB_SIZE;
page_count = 0;
SetFont(COURIER, 10);
DocumentSetup();
row = start_y;
line_count = lines_per_page;
SetHeaderFont(COURIER_BOLD, 15);
}
PostScriptDrv::PostScriptDrv(const PostScriptDrv &ob)
{
ncopies = ob.ncopies;
landscape = ob.landscape;
lines_per_page = ob.lines_per_page;
columns = ob.columns;
tabstop = ob.tabstop;
row = ob.row;
start_x = ob.start_x;
start_y = ob.start_y;
page_count = ob.page_count;
font_size = ob.font_size;
page_width = ob.page_width;
page_height = ob.page_height;
chars_per_inch = ob.chars_per_inch;
char_width = ob.char_width;
text_font = ob.text_font;
use_lr_margin = ob.use_lr_margin;
use_tb_margin = ob.use_tb_margin;
use_header = ob.use_header;
header_font = ob.header_font;
header_font_size = ob.header_font_size;
document_name = ob.document_name;
date_string = ob.date_string;
draw_header_line = ob.draw_header_line;
line_count = ob.line_count;
}
PostScriptDrv &PostScriptDrv::operator=(const PostScriptDrv &ob)
{
ncopies = ob.ncopies;
landscape = ob.landscape;
lines_per_page = ob.lines_per_page;
columns = ob.columns;
tabstop = ob.tabstop;
row = ob.row;
start_x = ob.start_x;
start_y = ob.start_y;
page_count = ob.page_count;
font_size = ob.font_size;
page_width = ob.page_width;
page_height = ob.page_height;
text_font = ob.text_font;
chars_per_inch = ob.chars_per_inch;
char_width = ob.char_width;
use_lr_margin = ob.use_lr_margin;
use_tb_margin = ob.use_tb_margin;
use_header = ob.use_header;
header_font = ob.header_font;
header_font_size = ob.header_font_size;
document_name = ob.document_name;
date_string = ob.date_string;
draw_header_line = ob.draw_header_line;
line_count = ob.line_count;
return *this;
}
void PostScriptDrv::SetFont(PSFonts font, double size)
{
switch(font){
case COURIER:
font_size = size;
char_width = 0.6 * font_size; // Width of each character
break;
case COURIER_BOLD:
font_size = size;
char_width = 0.6 * font_size; // Width of each character
break;
case COURIER_OBLIQUE:
font_size = size;
char_width = 0.6 * font_size; // Width of each character
break;
case COURIER_BOLD_OBLIQUE:
font_size = size;
char_width = 0.6 * font_size; // Width of each character
break;
case TIMES:
font_size = size;
char_width = 0.57 * font_size; // Width of each character
break;
case TIMES_BOLD:
font_size = size;
char_width = 0.6 * font_size; // Width of each character
break;
case TIMES_ITALIC:
font_size = size;
char_width = 0.55 * font_size; // Width of each character
break;
case TIMES_BOLD_ITALIC:
font_size = size;
char_width = 0.58 * font_size; // Width of each character
break;
case HELV:
font_size = size;
char_width = 0.6 * font_size; // Width of each character
break;
case HELV_BOLD:
font_size = size;
char_width = 0.6 * font_size; // Width of each character
break;
case HELV_OBLIQUE:
font_size = size;
char_width = 0.6 * font_size; // Width of each character
break;
case HELV_BOLD_OBLIQUE:
font_size = size;
char_width = 0.6 * font_size; // Width of each character
break;
case SYMBOL:
font_size = size;
char_width = 0.57 * font_size; // Width of each character
break;
default: // COURIER
font_size = DEFAULT_POINT_SIZE;
char_width = 0.6 * font_size; // Width of each cha